package com.ct.gd.passport.view.consult;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.ct.gd.passport.R;
import com.ct.gd.passport.common.BaseActivity;
import com.ct.gd.passport.domain.AdviceDetail;
import com.ct.gd.passport.view.BundleKeys;
import com.ct.gd.passport.view.widget.CustomHeaderFragment;
import com.up91.common.android.async.ILoading;
import com.up91.common.android.async.SimpleAsyncTask;

public class ConsultDetailActivity extends BaseActivity {

	private FragmentManager mFgMan;
	private CustomHeaderFragment mFgHeader;
	
//	private TextView	mTitle;
	private TextView	mSubmitContent;
	private TextView	mSubmitTime;
	private TextView	mReplyPerson;
	private TextView	mReplyContent;
	private TextView	mReplyTime;

	@Override
	protected void onBaseCreate(Bundle savedInstanceState) {
		setContentView(R.layout.consult_detail);
	}

	@Override
	protected void initViews() {
		mFgMan = getSupportFragmentManager();
		mFgHeader = (CustomHeaderFragment)mFgMan.findFragmentById(R.id.header);
		mFgHeader.setCenterText(R.string.advice_list);
		
//		mTitle = (TextView) findViewById(R.id.tv_advice_detail_title);
		mSubmitContent = (TextView) findViewById(R.id.tv_advice_detail_submit_content);
		mSubmitTime = (TextView) findViewById(R.id.tv_advice_detail_submit_time);
		mReplyPerson = (TextView) findViewById(R.id.tv_advice_detail_reply_person);
		mReplyContent = (TextView) findViewById(R.id.tv_advice_detail_reply_content);
		mReplyTime = (TextView) findViewById(R.id.tv_advice_detail_reply_time);
	}

	@Override
	protected void onAfterCreate(Bundle savedInstanceStat) {
		int adviceId = getIntent().getIntExtra(BundleKeys.ADVICE_ID, 0);
		new GetAdviceDetailTask(this, true).execute(adviceId);
	}

	private class GetAdviceDetailTask extends SimpleAsyncTask<Integer, Void, AdviceDetail> {

		public GetAdviceDetailTask(ILoading loading, boolean showLoading) {
			super(loading, showLoading);
		}

		@Override
		protected AdviceDetail onLoad(Integer... params) throws Exception {
			int adviceId = params[0];
			return AdviceDetail.load(adviceId);
		}

		@Override
		protected void onUI(AdviceDetail result) {
//			mTitle.setText(result.getTitle());
			mSubmitContent.setText(result.getSubmitContent());
			mSubmitTime.setText(result.getSubmitTime());
			if(!TextUtils.isEmpty(result.getReplyContent())){
				findViewById(R.id.area_consult_detail_reply).setVisibility(View.VISIBLE);
				mReplyPerson.setText(result.getReplyPerson() + ":");
				mReplyContent.setText(result.getReplyContent());
				mReplyTime.setText(result.getReplyTime());
			}
		}
	}
}
